//
//  CTPNavViewController.m
//  LittleNotes
//
//  Created by 檀志文 on 16/5/19.
//  Copyright © 2016年 ios檀志文. All rights reserved.
//

#import "CTPNavViewController.h"
#import "UIImage+Enlarge.h"

@interface CTPNavViewController ()

@end

@implementation CTPNavViewController
//+ (void)load {
//    [[UINavigationBar appearance] setBackgroundImage:[UIImage loadAnOldImageName:@"CTPNav"] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
//}
// 如果子类没有重写该方法，父类的该方法会被调用多次
+ (void)initialize {
    if (self == [CTPNavViewController self]) {
        // 获得主题导航条
        UINavigationBar *navBar = [UINavigationBar appearance];
        
        // 设置返回按钮的箭头颜色
        navBar.tintColor = [UIColor whiteColor];
        
        // 设置导航条背景
        [navBar setBackgroundColor:CMTGlobalColor];
        [navBar setBackgroundImage:[UIImage loadAnOldImageName:@"CTPNav"] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
        
        // 设置导航条标题颜色
        NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
        attributes[NSFontAttributeName] = [UIFont systemFontOfSize:14];
        attributes[NSForegroundColorAttributeName] = [UIColor whiteColor];
        [navBar setTitleTextAttributes:attributes];
        
        // 获得全局的item
        UIBarButtonItem *item = [UIBarButtonItem appearance];
        NSMutableDictionary *itemAttributes = [NSMutableDictionary dictionary];
            itemAttributes[NSFontAttributeName] = [UIFont systemFontOfSize:14];
        itemAttributes[NSForegroundColorAttributeName] = [UIColor whiteColor];
        [item setTitleTextAttributes:itemAttributes forState:UIControlStateNormal];
    }
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    viewController.hidesBottomBarWhenPushed = YES;
    [super pushViewController:viewController animated:animated];
}

@end
